package com.itclass.auth.handler.authentication.support;

import cn.hutool.json.JSONUtil;
import com.itclass.auth.constant.RedisCacheKeyConstants;
import com.itclass.auth.handler.authentication.AbstractAuthenticationSuccessHandler;
import com.itclass.auth.pojo.db.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class LogingAuthenticationSuccessHandler implements AuthenticationSuccessHandler {


    @Autowired
    private List<AbstractAuthenticationSuccessHandler> authenticationSuccessHandlers;

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        for (AbstractAuthenticationSuccessHandler authenticationSuccessHandler : authenticationSuccessHandlers) {
            if (authenticationSuccessHandler.supports(authentication.getClass())) {
                authenticationSuccessHandler.onAuthenticationSuccess(request,response,authentication);
                break;
            }
        }

    }
}
